let arr = [2, 1, 7, 4, 3, 1, 6, 5]


function insert_sort(arr) {
  const len = arr.length
  let target
  for (let i = 1; i < len; i++) {
    if (arr[i] >= arr[i - 1]) continue
    target = arr[i]
    let j = i - 1
    // 遍历已经有序的值，找到target应在的位置
    while (arr[j] > target) {
      arr[j + 1] = arr[j]
      j--
    }
    arr[j + 1] = target
  }
  return arr
}
console.log(insert_sort(arr));
